package com.zzsource.yuapicliensdk.service.impi;


import com.zzsource.yuapicliensdk.client.YuApiClient;
import com.zzsource.yuapicliensdk.exception.ApiException;
import com.zzsource.yuapicliensdk.exception.ErrorCode;
import com.zzsource.yuapicliensdk.model.request.*;
import com.zzsource.yuapicliensdk.model.response.*;
import com.zzsource.yuapicliensdk.service.ApiService;
import com.zzsource.yuapicliensdk.service.BaseService;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;

/**
 * @Author: QiMu
 * @Date: 2023年09月17日 08:42
 * @Version: 1.0
 * @Description:
 */
@Slf4j
public class ApiServiceImpl extends BaseService implements ApiService {
    @Override
    public PoisonousChickenSoupResponse getPoisonousChickenSoup() throws ApiException {
        PoisonousChickenSoupRequest request = new PoisonousChickenSoupRequest();
        return request(request);
    }

    @Override
    public PoisonousChickenSoupResponse getPoisonousChickenSoup(YuApiClient yuApiClient) throws ApiException {
        PoisonousChickenSoupRequest request = new PoisonousChickenSoupRequest();
        return request(yuApiClient, request);
    }

    @Override
    public RandomJokeResponse getRandomJoke() throws ApiException {
        RandomJokeRequest request = new RandomJokeRequest();
        return request(request);
    }

    @Override
    public RandomJokeResponse getRandomJokeResponse(YuApiClient yuApiClient) throws ApiException {
        RandomJokeRequest request = new RandomJokeRequest();
        return request(yuApiClient, request);
    }

    @Override
    public ACGImgResponse getACGImg() throws ApiException {
        ACGImgRequest request = new ACGImgRequest();
        return request(request);
    }

    @Override
    public ACGImgResponse getACGImg(YuApiClient yuApiClient) throws ApiException {
        ACGImgRequest request = new ACGImgRequest();
        return request(yuApiClient, request);
    }

    @Override
    public BiResponse getOpenGenChartByAi(OpenGenChartByAiRequest openGenChartByAiRequest) throws ApiException {
        return request(openGenChartByAiRequest);
    }

    @Override
    public BiResponse getOpenGenChartByAi(OpenGenChartByAiRequest openGenChartByAiRequest, YuApiClient yuApiClient) throws ApiException {
        return request(yuApiClient, openGenChartByAiRequest);
    }

    @Override
    public <O, T extends ResultResponse> T request(BaseRequest<O, T> request) throws ApiException {
        try {
            return res(request);
        } catch (Exception e) {
            throw new ApiException(ErrorCode.OPERATION_ERROR, e.getMessage());
        }
    }

    @Override
    public <O, T extends ResultResponse> T request(YuApiClient yuApiClient, BaseRequest<O, T> request) throws ApiException {
        checkConfig(yuApiClient);
        return request(request);
    }

}
